package com.qf.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.qf.annotation.RequiresPermissionsDesc;
import com.qf.pojo.DtsRegion;
import com.qf.service.DtsRegionService;
import com.qf.util.ResponseUtil;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;

/**
 * @author Cc
 * @version 1.0
 * 行政区域
 */
@RestController
@CrossOrigin("*")
@RequestMapping("/admin/region")
public class AdminRegionController {

    @Autowired
    private DtsRegionService regionService;


    /**
     * 行政区域列表
     * 接口地址 : http://localhost:8083/admin/region/list?page=1&limit=20
     */
    @RequiresPermissions("admin:region:list")
    @RequiresPermissionsDesc(menu = {"商场管理", "行政区域"}, button = "查询")
    @GetMapping("/list")
    public Object list(String name, @RequestParam(defaultValue = "1") Integer page,
                       @RequestParam(defaultValue = "10") Integer limit,
                       String sort, String order) {
        IPage<DtsRegion> iPage = regionService.querySelective(name, page, limit, sort, order);

        HashMap map = new HashMap();

        map.put("total", iPage.getTotal());
        map.put("items", iPage.getRecords());
        return ResponseUtil.ok(map);
    }
}
